package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.WorkOrder;
import cn.stylefeng.guns.sys.modular.system.model.params.WorkOrderParam;
import cn.stylefeng.guns.sys.modular.system.service.WorkOrderService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/workOrder")
public class WorkOrderController {

    private String PREFIX = "/modular/system/workOrder";

    @Autowired
    private WorkOrderService workOrderService;

    /**
     * 跳转到主页面
     *
     * @author
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/workOrder.html";
    }

    /**
     * 新增页面
     *
     * @author
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/workOrder_add.html";
    }

    /**
     * 编辑页面
     *
     * @author
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/workOrder_edit.html";
    }

    /**
     * 新增接口
     *
     * @author
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(WorkOrderParam workOrderParam) {
        return this.workOrderService.add(workOrderParam);
    }


    /**
     * 编辑接口
     *
     * @author
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(WorkOrderParam workOrderParam) {
        return this.workOrderService.update(workOrderParam);
    }


    /**
     * 删除接口
     *
     * @author
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(WorkOrderParam workOrderParam) {
        return this.workOrderService.delete(workOrderParam);
    }

    /**
     * 查看详情接口
     *
     * @author
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(WorkOrderParam workOrderParam) {
        WorkOrder detail = this.workOrderService.getById(workOrderParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(WorkOrderParam workOrderParam) {
        return this.workOrderService.findPageBySpec(workOrderParam);
    }

    /**
     * 查询人员列表
     *
     * @return
     */
    @RequestMapping(value = "/getUserList")
    @ResponseBody
    public List<Map> getUserList() {
        List<Map> maps = workOrderService.getUserList();
        return maps;
    }

}
